package cn.ycbjie.ycaudioplayer.newpack.linkagescroll.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.TextView;



import java.util.List;

import cn.ycbjie.ycaudioplayer.R;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.holder.RecyclerItemViewHolder;
import cn.ycbjie.ycaudioplayer.newpack.linkagescroll.mybeans.MyPlayerlistBean;

/**
 * Created by GUO on 2015/12/3.
 */

/**
 * Created by Nelson on 15/11/9.
 */
public class RecyclerBaseAdapter extends RecyclerView.Adapter {

    private final static String TAG = "RecyclerBaseAdapter";

    private List<MyPlayerlistBean> itemDataList = null;
    private Context context = null;
    TextView title;
    private AdapterView.OnItemClickListener mOnItemClickListener;

    public RecyclerBaseAdapter(Context context, List<MyPlayerlistBean> itemDataList) {
        this.itemDataList = itemDataList;
        this.context = context;
    }

//    public void setOnItemClickListener(OnItemClickListener clickListener)
//    {
//        mc.mOnItemClickListener = clickListener;
//    }
//    public interface OnItemClickListener { void onItemClick(View view, int position); }
//    private OnItemClickListener mOnItemClickListener;//声明接口
//
//    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
//        mOnItemClickListener = onItemClickListener;
//    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                      int viewType) {
        View v = LayoutInflater.from(context).inflate(R.layout.list_item_layout, parent, false);
        final RecyclerView.ViewHolder holder = new RecyclerItemViewHolder(context, v);
//        final holder.title Textview title;
        return holder;


//        View viewHolder = LayoutInflater.from(context).inflate(R.layout.list_item_layout, parent, false);
//        final RecyclerView.ViewHolder holder = new RecyclerItemViewHolder(context, viewHolder);

//        viewHolder.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                viewHolder.item.onItemClick(v);
//            }
//        });
//        viewHolder.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                viewHolder.onItemLongClick(v);
//                return true;
//            }
//        });





//         title = viewHolder.findViewById(R.id.tv_playerlist_title);
//        return holder;

    }
//    class ListViewHolder extends RecyclerView.ViewHolder {
//        TextView title;
//
//        public ListViewHolder(View itemView) {
//            super(itemView);
//            title = (TextView) itemView.findViewById(R.id.tv_playerlist_title);
//        }
//    }
    @Override
    public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
//        holder.title
       title.setText(itemDataList.get(position).getTitle());
//        View itemView = null;
//        try {
//            itemView = ((RelativeLayout) holder.itemView).getChildAt(0);
//       }
//       catch (Exception ex)
//       {
//           ex.printStackTrace();
//       }
//
//        if (mOnItemClickListener != null) {
//            itemView.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    int position = holder.getLayoutPosition();
//                    mOnItemClickListener.onItemClick(holder.itemView, position);
//                }
//            });
//        }


    }

    @Override
    public int getItemCount() {
       return itemDataList.size();
    }


    @Override
    public int getItemViewType(int position) {
        return 1;
    }

    public void setListData(List<MyPlayerlistBean> data) {
        itemDataList = data;
        notifyDataSetChanged();
    }

}
